<%@ page contentType="text/html; charset=UTF-8" language="java"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>票务类型管理 </title>
		<%@ include file="/WEB-INF/jspf/taglibs.jspf"%>
		<%@ include file="/WEB-INF/jspf/statics.jspf"%>
</head>
<body>
<div id="wrapper">

    <div class="submit-form pusht">
        <form name="submit-form" id="submit-form">
            <table class="form label-colored-form">
                <c:if test="${operationType=='add'}"> 
                    <tbody>
                    <tr class="sprite">
                        <td class="label-td"><label>票务名称：</label></td>
                        <td><input type="text" name="ticketTypeName" id="ticketTypeName" value="" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>票务类型：</label></td>
                        <td>
                            <select name="ticketType" id="ticketType">
                                <option value=1>收费</option>
                                <option value=2>免费</option>
                                <option value=3>赠票</option>
                            </select>
                        </td>
                    </tr>
                    
                    <tr class="sprite">
                       <td class="label-td"><label>挂牌价：</label></td>
                       <td><!-- <input type="text" value="" name="marketPrice" maxlength="20" style="width:200px;"> -->
                       <input type="text" name="marketPrice" id="marketPrice" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" style="width:200px;" /><span>*(只能输入数字和小数点)</span> </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>学生价：</label></td>
                        <td><input type="text" name="studentPrice" id="studentPrice" value="" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" maxlength="20" style="width:200px;"><span>*(只能输入数字和小数点)</span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>老人价：</label></td>
                        <td><input type="text" name="oldManPrice" id="oldManPrice" value="" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" maxlength="20" style="width:200px;"><span>*(只能输入数字和小数点)</span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>军人价：</label></td>
                        <td><input type="text" name="armyManPrice" id="armyManPrice"onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"value="" maxlength="20" style="width:200px;"><span>*(只能输入数字和小数点)</span></td>
                    </tr>
                   <tr class="sprite">
                        <td class="label-td"><label>状态：</label></td>
                        <td>
                            <select name="status" id="status">
                             	<option value=2>禁用</option>
                                <option value=1>启用</option>
                            </select>
                        </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label></label></td>
                        <td>
                            <button class="btn btn-primary" id="btn_confirm">添加</button>
                        </td>
                    </tr>
                    </tbody>
                </c:if>
                
                
                <c:if test="${operationType !='add'}">
                    <tbody>
                     <tr class="sprite">
                        <td class="label-td"><label>票务编号：</label></td>
                        <td><input type="text" name="ticketNo" id="ticketNo" value="${ticket.ticketNo }" readonly="readonly" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>票务名称：</label></td>
                        <td><input type="text" name="ticketTypeName" id="ticketTypeName" value="${ticket.ticketTypeName }" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>票务类型：</label></td>
                        <td>
                            <select name="ticketType" id="ticketType">
                                <option value=1 <c:if test="${ticket.ticketType==1 }">selected</c:if>>收费</option>
                                <option value=2 <c:if test="${ticket.ticketType==2 }">selected</c:if>>免费</option>
                                <option value=3 <c:if test="${ticket.ticketType==3 }">selected</c:if>>赠票</option>
                            </select>
                        </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>挂牌价：</label></td>
                        <td><input type="text" name="marketPrice" id="marketPrice" value="${ticket.marketPrice }" maxlength="20" style="width:200px;"><span>*(只能输入数字和小数点)</span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>学生价：</label></td>
                        <td><input type="text" name="studentPrice" id="studentPrice" value="${ticket.studentPrice }" maxlength="20" style="width:200px;"><span>*(只能输入数字和小数点)</span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>老人价：</label></td>
                        <td><input type="text" name="oldManPrice" id="oldManPrice" value="${ticket.oldManPrice }" maxlength="20" style="width:200px;"><span>*(只能输入数字和小数点)</span></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>军人价：</label></td>
                        <td><input type="text" name="armyManPrice" id="armyManPrice" value="${ticket.armyManPrice }" maxlength="20" style="width:200px;"><span>*(只能输入数字和小数点)</span></td>
                    </tr>
                   <tr class="sprite">
                        <td class="label-td"><label>状态：</label></td>
                        <td>
                            <select name="status" id="status">
                                <option value=1 <c:if test="${ticket.status==1 }">selected</c:if>>启用</option>
                                <option value=2 <c:if test="${ticket.status==2 }">selected</c:if>>禁用</option>
                            </select>
                        </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label></label></td>
                        <td>
                            <button class="btn btn-primary" id="btn_confirm1">保存</button>
                        </td>
                    </tr>
                    </tbody>
                </c:if>
            </table>
        </form>
    </div>
</div>
</body>
</html>
<%-- <script type="text/javascript" src="<%=basePath%>/js/banana.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/showBo.js"></script> --%>
<script type="text/javascript">
var checkTicketResult;
  $(document).ready(function () {
      // 给确认按钮绑定点击事件
      $("#btn_confirm").click(function (e) {
          e.preventDefault();
          if(subimtBtn('add')){
          	dialog_close();
          }
      });

      $("#btn_confirm1").click(function (e) {
          e.preventDefault();
          if(subimtBtn('update')){
          	dialog_close();
          }
          
      });
      function remAttr(){
          $("#marketPrice,#studentPrice,#oldManPrice,#armyManPrice").attr("disabled",false);
 	  }

     function  addAttr(){
          $("#marketPrice,#studentPrice,#oldManPrice,#armyManPrice").attr("disabled",true);
     }
      $("#ticketType").change(function(){
    	  if($(this).val()==2){
    		  addAttr();
    	  }else{
    		  remAttr();
    	  }
      })
      $("#ticketTypeName").focus(function(){
    	  $("#ticketTypeName").next().text('');
      });
      $("#studentPrice,#oldManPrice,#armyManPrice,#marketPrice").focus(function(){
    	  $(this).next().text('*(只能输入数字和小数点)');
      });
      
      $.ajaxSetup({
          async : false
      });
      $.post("<%=basePath%>order/check_ticket_status",function(data){
    	  checkTicketResult=data;
      });
  });
  
  function checkForm(){
	  values = $("#submit-form").serializeArray();  
	  var values, index;  
	  var result=true;
	  
	     for (index = 0; index < values.length; ++index)  
	    {  
	      if (values[index].name == "ticketTypeName")  
	      {  
	    	  if(values[index].value=="" || values[index].value==null){
	    		  result=false;
	    		  $("#ticketTypeName").next().text("票务类型名称不能为空!");
	    		  break;
	    	  }    	  
	      }
	      if (values[index].name == "oldManPrice" || values[index].name == "studentPrice"||values[index].name == "armyManPrice")  
	      {  
	    	  if($("#ticketType").val()!=2){
	    		  if(values[index].value==null || values[index].value==""){
	    			  $("#"+values[index].name).next().text("*价格不能为空！！");
	    			  result=false;
	    		  }else if(Number(values[index].value) >Number($("#marketPrice").val())){
	  	   			  result=false;
	  	   			  $("#"+values[index].name).next().text("*价格不能大于挂牌价！");
	  	   		  }  
	    	  }
	   		  
	      }
	     
	    } 
   	  if($("#status").val()==1 && checkTicketResult=="existence"){
   	        if(!confirm("设置为启用状态，其他票务类型将自动被设置为禁用状态！")){
   	            return false;
   	        }
   	  }else if($("#status").val()==2 && checkTicketResult=="uexistence"){
   		  alert('必须设置一种启用一种票务类型');
   		  return false;
   	  }
	     
	     return result;
  }
  
  function subimtBtn(type) {  
	  if(!checkForm()){
		  return false;
	  }
      var url="<%=basePath%>/order/update_ticket/"+type;  
	  $.post(url,$("#submit-form").serializeArray(),function(json){
		  if (json == "success") {
            	parent.document.getElementById('success').click();
            } else {
            	parent.document.getElementById('fail').click();
            }
	  })
      dialog_close({callBack: function () {
          parent.document.getElementById('btn-primary').click();
      }});
  }  
</script>